package com.wangcang.widgetlibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.bean.AddressBean;

import java.util.List;

/**
 * Created by mundane on 2016/12/6 18:56
 */

public class AddressDemoAdapter extends BaseAdapter {
	private Context mContext;
	private List<AddressBean> mList;
	private LayoutInflater mLayoutInflater;

	public AddressDemoAdapter(Context context, List<AddressBean> list) {
		mContext = context;
		mList = list;
		mLayoutInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public AddressBean getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AddressViewHolder holder;
		AddressBean itemData = mList.get(position);
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.item_select_address, parent, false);
			holder = new AddressViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (AddressViewHolder) convertView.getTag();
		}
		holder.tvAddressName.setText(itemData.getAREA_NAME());
		if (itemData.isCheck()) {
			holder.tvAddressName.setTextColor(mContext.getResources().getColor(R.color.common_color_c1_337cff));
			holder.tvAddressName.getPaint().setFakeBoldText(true);
			holder.ivIcon.setVisibility(View.VISIBLE);
		} else {
			holder.tvAddressName.setTextColor(mContext.getResources().getColor(R.color.common_color_c5_45494e));
			holder.tvAddressName.getPaint().setFakeBoldText(false);
			holder.ivIcon.setVisibility(View.GONE);
		}
		return convertView;
	}

	static class AddressViewHolder {
		TextView tvAddressName;
		ImageView ivIcon;

		public AddressViewHolder(View view) {
			this.tvAddressName = (TextView) view.findViewById(R.id.tv_address_name);
			this.ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
		}
	}

}
